#include <iostream>
#include <cstdlib>

using namespace std;

class Vec4 {
	private:
		float vector[4];
	
	public:
		Vec4(float a0=0, float b0=0, float c0=0, float d0=0) {
				vector[0]=a0; 
				vector[1]=b0; 
				vector[2]=c0;
				vector[3]=d0;
		}
		Vec4(const Vec4 & obj);
		~Vec4() {};

	    float operator[] (int i);

		friend Vec4  operator + (Vec4 & obj1, Vec4 & obj2);
		friend Vec4  operator - (Vec4 & obj1, Vec4 & obj2);
		float operator * (Vec4 & obj);
		Vec4 operator * (float i);
		Vec4 operator / (float i);
		//friend Vec4 & operator / (Vec4 & obj1, Vec4 & obj2);

		friend Vec4 & operator += (Vec4 & obj1, Vec4 & obj2);
		friend Vec4 & operator -= (Vec4 & obj1, Vec4 & obj2);
		// Vec4 & operator *= (Vec4 & obj);
		Vec4 & operator *= (float n);
		Vec4 & operator /= (float n);
		// friend Vec4 & operator /= (Vec4 & obj1, Vec4 & obj2);

		friend ostream & operator << (ostream & stream, const Vec4 & obj);
};

Vec4::Vec4(const Vec4 & obj) {
	for(int i=0; i<4; i++) {
		vector[i] = obj.vector[i];
	}
}

float Vec4::operator[] (int i) {
	if( i>= 4) {
		cout << "Illegal Digist. ";
		// exit(-1);
	} else {
		return vector[i];
	}
}

Vec4 operator + (Vec4 & obj1, Vec4 & obj2) {
	Vec4 temp;
	for(int i=0; i<4; i++) {
		temp.vector[i] = obj1.vector[i] + obj2.vector[i];
	}
	
	return temp;
}

Vec4 operator - (Vec4 & obj1, Vec4 & obj2) {
	Vec4 temp;
	for(int i=0; i<4; i++) {
		temp.vector[i] = obj1.vector[i] - obj2.vector[i];
	}

	return temp;
}

float Vec4::operator * (Vec4 & obj) {
	float temp;
	for(int i=0; i<4; i++) {
		temp += (vector[i] * obj.vector[i]);
	}

	return temp;
}

Vec4 Vec4::operator * (float n) {
	Vec4 temp;
	for(int i=0; i<4; i++) {
		temp.vector[i] = vector[i] * n;
	}

	return temp;
}

Vec4 Vec4::operator / (float n) {
	Vec4 temp;
	for(int i=0; i<4; i++) {
		temp.vector[i] = vector[i] / 4;
	}
	
	return temp;
}

Vec4 & operator+= (Vec4 & obj1, Vec4 & obj2) {
	for(int i=0; i<4; i++)
		obj1.vector[i] += obj2.vector[i];

	return obj1;
}

Vec4 & operator -= (Vec4 & obj1, Vec4 & obj2) {
	for(int i=0; i<4; i++)
		obj1.vector[i] -= obj2.vector[i];

	return obj1;
}

Vec4 & Vec4::operator*= (float n) {
	for(int i=0; i<4; i++)
		vector[i] *= n;

	return *this;
}

Vec4 & Vec4::operator/= (float n) {
	for(int i=0; i<4; i++)
		vector[i] /= n;

	return *this;
}

ostream & operator << (ostream & stream, const Vec4 & obj) {
	stream << "(";
	for(int i=0; i<3; i++)
		stream << obj.vector[i] << ",";
	stream << obj.vector[3] << ")";

	return stream;
}

int main(void) {
	Vec4 obj1;

	cout << "New Vec4 obj: " << obj1 << endl;

	Vec4 obj2(1,2,3,4), obj3(5,6,7,8), obj4;
	obj4 = obj2 + obj3;
	cout << obj2 << " + " << obj3 << " = " << obj4 << endl;
	cout << obj2 << " * " << obj3 << " = " << obj2*obj3 << endl;
	cout << obj2 << " * " << "3" << " = " << obj2*3 << endl;
	//cout << "2" << " * " << obj3 << " = " << 2*obj3 << endl;

	cout << endl << obj2 << " *= 5"<< " --> new obj2 = "; 
	obj2 *= 5;
	cout << obj2 << endl;

	cout << endl << obj2 << " /= 10"<< " --> new obj2 = "; 
	obj2 /= 10;
	cout << obj2 << endl;
	
	Vec4 obj5(2,0,1,4);
	cout << endl << obj5 << endl;
	for(int i=0; i<6; i++) {
		cout << "Obj[" << i << "] = " << obj5[i] << endl;
	}

	return 0;
}
